package com.galaxy.device.api;

import com.galaxy.common.core.domain.R;
import com.galaxy.device.domain.vo.ProductVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 商品服务降级处理
 */
@Component
public class RemoteProductFallbackFactory implements FallbackFactory<RemoteProductService> {
    private static final Logger log = LoggerFactory.getLogger(RemoteProductFallbackFactory.class);

    @Override
    public RemoteProductService create(Throwable throwable) {
        log.error("商品服务调用失败:{}", throwable.getMessage());
        return new RemoteProductService() {
            @Override
            public R<ProductVo> getInfo(Long id) {
                return R.fail("获取商品信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<ProductVo>> getBatchInfo(List<Long> ids) {
                return R.fail("获取商品信息失败:" + throwable.getMessage());
            }
        };
    }
}
